<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Codemirror Playground</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/codemirror.min.css" rel="stylesheet">
	<script src="https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/codemirror.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/mode/javascript/javascript.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/addon/display/autorefresh.min.js"></script>
	<script src="/main.cjs.js"></script>
	<link href="https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/theme/material.min.css" rel="stylesheet">
	<style>
		body {
			margin: 0;
		}
	</style>
</head>

<body>
	<h1>Playground (测试中)</h1>
	<textarea id="editor" name="code">// 在这里编写代码
kkutils;
      </textarea>
	<input type="text" @input="limitAmount">
	<button onclick="runCode()">Run</button>
	<div id="console" style="white-space: pre-wrap;"></div>

	<script>

		// const consoleArea = document.getElementById('console');
		// console.log = function(message) {
		//   console.warn(  message)
		//   consoleArea.value += message + '\n';
		// }

		var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
			lineNumbers: true,
			mode: "javascript",
			theme: "material",
			viewportMargin: Infinity,
			lineWrapping: true,
			matchBrackets: true,
			autoCloseBrackets: true,
		});

		editor.on("change", function () {
			runCode()
		});
		function runCode () {
			var code = editor.getValue();
			console.log("code", code);
			var result = ""
			try {
				result = eval(code);
				// document.getElementById("console").innerHTML = String(result);
			} catch (error) {
				console.log("result~~~~~~~~", error);
				result = error.message
			}
			console.log("result", result);
			document.getElementById("console").innerHTML = jsonStringify(result);

		}
		function jsonStringify (obj) {
			if (typeof obj === 'function') {
				return obj.toString();
			}

			if (typeof obj !== 'object' || obj === null) {
				if (typeof obj === 'string') {
					return '"' + obj + '"';
				} else {
					return '' + obj;
				}
			}

			if (Array.isArray(obj)) {
				return '[' + obj.map(jsonStringify).join(',') + ']';
			}

			return '{' + Object.keys(obj).map(function (key) {
				return '"' + key + '":' + jsonStringify(obj[key]);
			}).join(',') + '}';
		}

	</script>


	<script>
		console.log("limitAmount", limitAmount)
		console.log("Fff",cloneDeep);
		//调试方法

	</script>
</body>

</html>